using System;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base.Exceptions;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DMPropRule objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DMPropRule.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDMPropRule
    {
        [SetUp]
        public override void SetupTest()
        {
            //Runs every time that any testmethod is executed
            base.SetupTest();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [TearDown]
        public override void TearDownTest()
        {
            //runs every time any testmethod is complete
            base.TearDownTest();
        }

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsDMPropRule.CreateUnsavedValidDMPropRule();
            //---------------Assert Precondition----------------
            Assert.IsFalse(String.IsNullOrEmpty(dmPropRule.PropRuleName), "Name Should not be null");
            //---------------Execute Test ----------------------
            string actualToString = dmPropRule.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmPropRule.PropRuleName, actualToString);
        }

        [Test]
        public void Test_ToString_NameNull()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsDMPropRule.CreateUnsavedValidDMPropRule();
            dmPropRule.PropRuleName = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(String.IsNullOrEmpty(dmPropRule.PropRuleName), "Name Should be null");
            //---------------Execute Test ----------------------
            string actualToString = dmPropRule.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmPropRule.PropRuleID.ToString(), actualToString);
        }

        [Test]
        public void Test_ToString_NameNull_PropRuleIDNull()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsDMPropRule.CreateUnsavedValidDMPropRule();
            dmPropRule.PropRuleName = null;
            dmPropRule.PropRuleID = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(String.IsNullOrEmpty(dmPropRule.PropRuleName), "Name Should be null");
            Assert.IsNull(dmPropRule.PropRuleID);
            //---------------Execute Test ----------------------
            string actualToString = dmPropRule.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("-unnamed PropRule-", actualToString);
        }

        [Test]
        public void Test_InsertNewPropRuleInfo()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsShared.CreateUnsavedValidPropRuleInfo();

            //---------------Assert Precondition----------------
            Assert.IsTrue(dmPropRule.Status.IsNew);

            //---------------Execute Test ----------------------
            dmPropRule.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(dmPropRule.Status.IsNew);
        }

        [Test]
        public void Test_DeletePropRuleInfo()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsShared.CreateSavedPropRuleInfo();

            //---------------Assert Precondition----------------
            Assert.IsFalse(dmPropRule.Status.IsNew);
            string message;
            Assert.IsTrue(dmPropRule.IsDeletable(out message));

            //---------------Execute Test ----------------------
            dmPropRule.MarkForDelete();
            dmPropRule.Save();

            //---------------Test Result -----------------------  
            Assert.IsTrue(dmPropRule.Status.IsNew);
            Assert.IsTrue(dmPropRule.Status.IsDeleted);
        }

        [Test]
        public void Test_UpdatePropRuleInfo()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsShared.CreateSavedPropRuleInfo();

            //---------------Assert Precondition----------------
            Assert.IsFalse(dmPropRule.Status.IsNew);
            string message;
            Assert.IsTrue(dmPropRule.IsEditable(out message));

            //---------------Execute Test ----------------------
            dmPropRule.Class = TestUtilsShared.GetRandomString();
            dmPropRule.Assembly = TestUtilsShared.GetRandomString();
            dmPropRule.Generated = true;
            dmPropRule.Message = TestUtilsShared.GetRandomString();
            dmPropRule.PropRuleName = TestUtilsShared.GetRandomString();

            dmPropRule.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(dmPropRule.Status.IsNew);
        }

        [Test]
        public void Test_LoadPropRuleInfo()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsShared.CreateSavedPropRuleInfo();
            BusinessObjectManager.Instance.ClearLoadedObjects();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropRule loadedDMPropRule = Broker.GetBusinessObject<DMPropRule>(dmPropRule.ID);

            //---------------Test Result -----------------------  
            Assert.IsFalse(loadedDMPropRule.Status.IsNew);
            Assert.AreEqual(loadedDMPropRule.ID, dmPropRule.ID);
            //TODO: When not using memory db Assert.AreNotSame(loadedDMClass, businessObjectInfo);
        }

//
//        [Test]
//        public void Test_GetBusinessObjectProperty()
//        {
//            //---------------Set up test pack-------------------
//
//            DMProperty dmProperty = TestUtilsShared.CreateSavedDMProperty(TestUtilsShared.CreateSavedDMClass());
//            DMPropRule dmPropRule = TestUtilsShared.CreateSavedPropRuleInfo(dmProperty);
//            BusinessObjectManager.Instance.ClearLoadedObjects();
//
//            //---------------Assert Precondition----------------
//            Assert.IsFalse(dmPropRule.Status.IsNew);
//
//            //---------------Execute Test ----------------------
//            DMProperty loadedDMProperty = dmPropRule.Property;
//
//            //---------------Test Result -----------------------
//            Assert.AreEqual(dmProperty.ID, loadedDMProperty.ID);
//        }

        [Test]
        public void TestCreateRule()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = TestUtilsShared.CreateSavedPropRuleInfo();
            //           BusinessObjectManager.Instance.ClearLoadedObjects();
            DMPropRuleParameter parameter = dmPropRule.PropRuleParameters.CreateBusinessObject();
            TestUtilsShared.UpdateRulewithValidData(parameter);


            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmPropRule.PropRuleParameters.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, dmPropRule.PropRuleParameters.Count);

            //Assert.AreEqual(1, businessObjectLoader.GetMemoryDatabase().Count);
            //---------------Execute Test ----------------------
            parameter.Save();

            //---------------Test Result -----------------------
            //Assert.AreEqual(2, businessObjectLoader.GetMemoryDatabase().Count);

            Assert.AreEqual(0, dmPropRule.PropRuleParameters.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, dmPropRule.PropRuleParameters.Count);
        }


        [Test]
        public void Test_InsertNewPropRule_Invalid()
        {
            //---------------Set up test pack-------------------
            DMPropRule dmPropRule = new DMPropRule();

            //---------------Assert Precondition----------------
            Assert.IsTrue(dmPropRule.Status.IsNew);

            //---------------Execute Test ----------------------
            try
            {
                dmPropRule.Save();
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (BusObjectInAnInvalidStateException ex)
            {
                StringAssert.Contains("Name' is a compulsory field and has no value", ex.Message);
            }
            Assert.IsTrue(dmPropRule.Status.IsNew);
        }

        [Test]
        public void Test_NullValueDoesNoRaiseError()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            Assert.IsTrue(defaultPropRule.Status.IsDirty);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("minLength", propRuleParameter.KeyName);
            Assert.IsNull(propRuleParameter.Value);
            //--------------- Execute Test ----------------------
            defaultPropRule.Save();
            //--------------- Test Result -----------------------
            Assert.IsFalse(defaultPropRule.Status.IsDirty);
        }

        [Test]
        public void Test_DefaultPropRule_MinLength_MustBeInt()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("minLength", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                propRuleParameter.Value = "aaaa";
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value 'aaaa' is not valid for 'minLength'. The value must be an integer", ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_MinLength_EmptyStringDoesNotRaiseError()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("minLength", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            propRuleParameter.Value = "";
            //---------------Test Result -----------------------
            Assert.AreEqual(null, propRuleParameter.Value);
        }

        [Test]
        public void Test_DefaultPropRule_MinLength_HasPrevValue_EmptyStringDoesNotRaiseError()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            const string value = "5";
            propRuleParameter.Value = value;
            //--------------- Test Preconditions ----------------          
            Assert.AreEqual("minLength", propRuleParameter.KeyName);
            Assert.AreEqual(value, propRuleParameter.Value);
            //--------------- Execute Test ----------------------
            propRuleParameter.Value = "";
            //---------------Test Result -----------------------
            Assert.AreEqual(null, propRuleParameter.Value);
        }

        [Test]
        public void Test_DefaultPropRule_MaxLength_MustBeInt()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[1];
            Assert.AreEqual("maxLength", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                propRuleParameter.Value = "aaaa";
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value 'aaaa' is not valid for 'maxLength'. The value must be an integer", ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_Min_MustBeNumeric()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_INT32;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(DMPropertyType.PROP_TYPE_INT32, dmProperty.PropertyTypeString);
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                propRuleParameter.Value = "aaaa";
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains("The value 'aaaa' is not valid for 'min'. The value must be numeric", ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_Min_EmptyStringDoesNotRaiseError()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_INT32;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            propRuleParameter.Value = "";
            //---------------Test Result -----------------------
            Assert.AreEqual(null, propRuleParameter.Value);
        }

        [Test]
        public void Test_DefaultPropRule_Max_MustBeNumeric()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_INT32;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                propRuleParameter.Value = "aaaa";
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains("The value 'aaaa' is not valid for 'max'. The value must be numeric", ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_Min_MustBeDateTime()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(DMPropertyType.PROP_TYPE_DATETIME, dmProperty.PropertyTypeString);
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                propRuleParameter.Value = "aaaa";
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value 'aaaa' is not valid for 'min'. The value must be a DateTime", ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_Max_MustBeDateTime()
        {
            //--------------- Set up test pack ------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                propRuleParameter.Value = "aaaa";
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value 'aaaa' is not valid for 'max'. The value must be a DateTime", ex.Message);
            }
        }


        [Test]
        public void Test_DefaultPropRule_MinLength_MustBeGreaterThanZero()
        {
            //--------------- Set up test pack ------------------
            const string value = "-1";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("minLength", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                propRuleParameter.Value = value;
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value '" + value + "' is not valid for 'minLength'. The value must be greater than zero",
                     ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_MaxLength_GT_MinLength()
        {
            //--------------- Set up test pack ------------------
            const string minValue = "10";
            const string maxValue = "5";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("minLength", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("maxLength", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                minPropRuleParameter.Value = minValue;
                maxPropRuleParameter.Value = maxValue;
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value '" + maxValue
                     + "' is not valid for 'maxLength'. The value cannot be less than the 'minLength'", ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_MinLength_LT_MaxLength()
        {
            //--------------- Set up test pack ------------------
            const string minValue = "10";
            const string maxValue = "5";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("minLength", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("maxLength", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                maxPropRuleParameter.Value = maxValue;
                minPropRuleParameter.Value = minValue;
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value '" + minValue
                     + "' is not valid for 'minLength'. The value cannot be greater than the 'maxLength'", ex.Message);
            }
        }


        [Test]
        public void Test_DefaultPropRule_Max_GT_Min()
        {
            //--------------- Set up test pack ------------------
            const string minValue = "10";
            const string maxValue = "5";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_INT32;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                minPropRuleParameter.Value = minValue;
                maxPropRuleParameter.Value = maxValue;
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value '" + maxValue + "' is not valid for 'max'. The value cannot be less than the 'min'",
                     ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_Min_LT_Max()
        {
            //--------------- Set up test pack ------------------
            const string minValue = "10";
            const string maxValue = "5";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_INT32;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                maxPropRuleParameter.Value = maxValue;
                minPropRuleParameter.Value = minValue;
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value '" + minValue + "' is not valid for 'min'. The value cannot be greater than the 'max'",
                     ex.Message);
            }
        }


        [Test]
        public void Test_DefaultPropRule_MaxDate_GT_MinDate()
        {
            //--------------- Set up test pack ------------------
            DateTime minDate = DateTime.Now.AddDays(10);
            DateTime maxDate = DateTime.Now.AddDays(-1);
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                minPropRuleParameter.Value = minDate.ToString();
                maxPropRuleParameter.Value = maxDate.ToString();
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value '" + maxDate + "' is not valid for 'max'. The value cannot be less than the 'min'",
                     ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_MinDate_LT_MaxDate()
        {
            //--------------- Set up test pack ------------------
            DateTime minDate = DateTime.Now.AddDays(10);
            DateTime maxDate = DateTime.Now.AddDays(-1);
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            try
            {
                maxPropRuleParameter.Value = maxDate.ToString();
                minPropRuleParameter.Value = minDate.ToString();
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("The value '" + minDate + "' is not valid for 'min'. The value cannot be greater than the 'max'",
                     ex.Message);
            }
        }

        [Test]
        public void Test_DefaultPropRule_Min_ShouldAllowToday()
        {
            //--------------- Set up test pack ------------------
            string today = "Today";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(DMPropertyType.PROP_TYPE_DATETIME, dmProperty.PropertyTypeString);
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            propRuleParameter.Value = today;
            //---------------Test Result -----------------------
            Assert.AreEqual(today, propRuleParameter.Value);
        }

        [Test]
        public void Test_DefaultPropRule_Min_ShouldAllowNow()
        {
            //--------------- Set up test pack ------------------
            string now = "Now";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(DMPropertyType.PROP_TYPE_DATETIME, dmProperty.PropertyTypeString);
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            propRuleParameter.Value = now;
            //---------------Test Result -----------------------
            Assert.AreEqual(now, propRuleParameter.Value);
        }


        [Test]
        public void Test_DefaultPropRule_max_ShouldAllowToday()
        {
            //--------------- Set up test pack ------------------
            string today = "Today";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(DMPropertyType.PROP_TYPE_DATETIME, dmProperty.PropertyTypeString);
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            propRuleParameter.Value = today;
            //---------------Test Result -----------------------
            Assert.AreEqual(today, propRuleParameter.Value);
        }


        [Test]
        public void Test_DefaultPropRule_max_ShouldAllowNow()
        {
            //--------------- Set up test pack ------------------
            string now = "Now";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(DMPropertyType.PROP_TYPE_DATETIME, dmProperty.PropertyTypeString);
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter propRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", propRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            propRuleParameter.Value = now;
            //---------------Test Result -----------------------
            Assert.AreEqual(now, propRuleParameter.Value);
        }


        [Test]
        public void Test_DefaultPropRule_MinDateGTMaxDate_ShouldAllowToday()
        {
            //--------------- Set up test pack ------------------
            DateTime minDate = DateTime.Now.AddDays(-10);
            string maxDate = "Today";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            maxPropRuleParameter.Value = maxDate;
            minPropRuleParameter.Value = minDate.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(maxDate, maxPropRuleParameter.Value);
        }

        [Test]
        public void Test_DefaultPropRule_MinDateGTMaxDate_ShouldAllowNow()
        {
            //--------------- Set up test pack ------------------
            DateTime minDate = DateTime.Now.AddDays(-10);
            string maxDate = "Now";
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            dmProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_DATETIME;
            DMPropRule defaultPropRule = dmProperty.DefaultPropRule;
            //--------------- Test Preconditions ----------------
            Assert.IsNotNull(defaultPropRule);
            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = defaultPropRule.PropRuleParameters;
            Assert.IsTrue(propRuleParameters.Count > 0);
            DMPropRuleParameter minPropRuleParameter = propRuleParameters[0];
            Assert.AreEqual("min", minPropRuleParameter.KeyName);
            DMPropRuleParameter maxPropRuleParameter = propRuleParameters[1];
            Assert.AreEqual("max", maxPropRuleParameter.KeyName);
            //--------------- Execute Test ----------------------
            maxPropRuleParameter.Value = maxDate;
            minPropRuleParameter.Value = minDate.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(maxDate, maxPropRuleParameter.Value);
        }
        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMPropRule propRule = new DMPropRule();
            dmProperty.DefaultPropRule = propRule;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelElement)propRule).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(dmProperty, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelElement propRule = new DMPropRule();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                propRule.Parent = new DMProperty();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the Property rule by setting the related Property object", exceptionThrown.Message);
        }
    }
}